import { utils } from '@h5app/sheep/utils'
import { acceptHMRUpdate, defineStore } from 'pinia'
import { computed, ref } from 'vue'

const userStorageName = utils.constants.storageName('user-info')
type SystemUserInfo = any
export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref<SystemUserInfo>()
    const token = ref<string>()

    const refresh = ref<boolean>(false)

    /** 删除持久化数据 */
    const removeStorageSync = () => {
      // uni.removeStorageSync(userStorageName)
      token.value = ''
    }

    return { userInfo, token, removeStorageSync, refresh }
  },
  {
    persist: {
      key: userStorageName,
    },
  },
)

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useUserStore, import.meta.hot))
}
